package com.f37.f37ex01.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.f37.f37ex01.bean.Customer;
import com.f37.f37ex01.mapper.CustomerMapper;
import com.f37.f37ex01.service.CustomerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 35837
 * @version 1.0
 * @since 2023-12-29 15:41:48
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
    @Resource
    private CustomerMapper customerMapper;

    @Override
    public Customer login(QueryWrapper<Customer> wrapper) {
        return customerMapper.selectOne(wrapper);
    }

    @Override
    public void register(String username, String password, String nick) {
        Date date = new Date();
        Customer customer = new Customer();
        customer.setUsername(username);
        customer.setPassword(password);
        customer.setNick(nick);
        customer.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
        customerMapper.insert(customer);
    }
}
